package pers.buyusan;

import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import pers.buyusan.bean.ConsumerComponent;

import java.io.IOException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class DubboConsumer {

    public static void main(String[] args) throws IOException,
            InterruptedException {
        AnnotationConfigApplicationContext context = new
                AnnotationConfigApplicationContext(ConsumerConfiguration.class);
        context.start();
        ConsumerComponent service =
                context.getBean(ConsumerComponent.class);
        ExecutorService executorService = Executors.newFixedThreadPool(100);

        executorService.submit(() -> {
            try {
                while (true) {
                    String hello = service.sayHello("world");
                }
                //System.out.println("result :" + hello);
            } catch (Exception e) {
                e.printStackTrace();
            }
        });
        executorService.submit(() -> {
            try {
                while (true) {
                    String hello = service.sayHaHaHa("world");
                }
                //System.out.println("result :" + hello);
            } catch (Exception e) {
                e.printStackTrace();
            }
        });
        executorService.submit(() -> {
            try {
                while (true) {
                    String hello = service.sayBye("world");
                }
                //System.out.println("result :" + hello);
            } catch (Exception e) {
                e.printStackTrace();
            }
        });

    }

    @Configuration
    @EnableDubbo(scanBasePackages = "pers.buyusan.bean")
    @PropertySource("classpath:/dubbo-consumer.properties")
    @ComponentScan(value = {"pers.buyusan.bean"})
    static class ConsumerConfiguration {
    }
}
